const Book = require('../models/Book')
const db = require('../db')
const _ = require('lodash')
const { debug } = require('../utils/constant')

//插入简历
function insertResume(resume) {
    return new Promise(async (resolve, reject) => {
        try {
            if (resume) {
                await db.insert(resume, 'admin_user')//添加的表名
                resolve()

            } else {
                reject(new Error('添加的信息不正确'))
            }
        } catch (e) {
            reject(e)
        }
    })
}

//更新简历
function updateResume(resume) {
    return new Promise(async (resolve, reject) => {
        try {
            if (resume) {
                await db.update(resume, 'admin_user' ,`where id='${resume.id}'`)//添加的表名
                resolve()
            } else {
                reject(new Error('修改的信息不正确'))
            }
        } catch (e) {
            reject(e)
        }
    })
}

//删除简历
function deleteResume(resumeId) {
    return new Promise(async (resolve, reject) => {
        if(resumeId){
        const sql = `delete from admin_user where id='${resumeId}'`
        db.querySql(sql).then(() => {
            resolve()
        })}
    else {
            reject(new Error('删除简历信息失败'))
        }
    })
}

module.exports = {
    insertResume,
    updateResume,
    deleteResume
}
